//
//  BaseViewController.swift
//  我的微博
//
//  Created by ZhangChao on 15/9/1.
//  Copyright © 2015年 ZhangChao. All rights reserved.
//

import UIKit

class BaseViewController: UITableViewController {

//    var userLogin = UserAccount.loadUserAccount()?.access_token != nil
    
    var userLogin = UserAccountViewModel.sharedUserAccount.userLogon
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // super.loadView方法是在加载View的时候调用的,
        userLogin ? super.loadView() : setupVistorView()
        
    }
    
    // 定义一个vistor的属性
    var vistorView : VistorLoginView?
    
    private func setupVistorView(){
        vistorView = VistorLoginView()
        // 替换根视图
        view = vistorView

//        view = VistorLoginView()
        
//        测试用
//        view.backgroundColor = UIColor.yellowColor()
                // 设置导航按钮
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "regestButtonClicked")
        
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: UIBarButtonItemStyle.Plain, target: self, action: "loginButtonClicked")
        
        vistorView?.registerButton.addTarget(self, action: "regestButtonClicked", forControlEvents: UIControlEvents.TouchUpInside)
        vistorView?.loginButton.addTarget(self, action: "loginButtonClicked", forControlEvents: UIControlEvents.TouchUpInside)
    }
    
        func regestButtonClicked (){
        
            
        }
        func loginButtonClicked (){
    
            let nav = UINavigationController(rootViewController: OAuthViewController())
            
            presentViewController(nav, animated: true, completion: nil)
        }
}
